#!/bin/bash
# ./run_jar.sh directory xxx.jar '-Dspring.profiles.active=dev'
# $1--目录 $2--jar文件 $3--启动参数 $4--筛选标记  

echo "stop $2 "

if [ -n "$4" ]
then
    pid=`ps -ef | grep $2 | grep $4 | grep -v grep | grep -v run_jar_nacos.sh | awk '{print $2}'`
else
    pid=`ps -ef | grep $2 | grep -v grep | grep -v run_jar_nacos.sh | awk '{print $2}'`
fi

if [ -n "$pid" ]
then
    echo "kill $2 $pid"
    kill $pid
fi

sleep 60

echo "start $2"
serverAddr="127.0.0.1:8848"
namespace="prod"
active="prod"
nohup java -Dspring.profiles.active=$active -Dspring.cloud.nacos.discovery.server-addr=$serverAddr -Dspring.cloud.nacos.config.server-addr=$serverAddr -Dspring.cloud.nacos.discovery.namespace=$namespace -Dspring.cloud.nacos.config.namespace=$namespace $3 -jar "$1/$2" > /dev/null 2>&1 &

